/*****************************************************************************/
/*                                                                           */
/*    Domino Operation System Kernel module                                  */
/*                                                                           */
/*    Copyright (C) 2005 Laszlo Arvai                                        */
/*                                                                           */
/*    ------------------------------------------------------------------     */
/*    krnlString.h - String handler function                                 */
/*****************************************************************************/
#ifndef __krnlString_H
#define __krnlString_H

///////////////////////////////////////////////////////////////////////////////
// Includes
#include "krnlTypes.H"
#include "sysCompiler.h"
#include <string.h>

///////////////////////////////////////////////////////////////////////////////
// Typedefs
typedef dosChar*	dosString;	// string
typedef char dosASCIIChar;
typedef char* dosASCIIString;

///////////////////////////////////////////////////////////////////////////////
// Constants

// string conversion options
#define TS_NO_ZERO_BLANKING (1<<1)
#define TS_RIGHT_ADJUSTMENT (1<<2)
#define TS_DISPLAY_MINUS_SIGN (1<<3)

// parser options
#define TS_ACCEPT_MINUS_SIGN (1<<1)


#define charIsDigit(x) ((x)>='0' && ((x))<='9')
#define charIsHexDigit(x) (((x)>='0' && ((x))<='9') || ((x)>='a' && ((x))<='f') || ((x)>='A' && ((x))<='F'))

// line end types
typedef enum
{
	dosString_LE_CR,
	dosString_LE_LF,
	dosString_LE_CRLF,
	dosString_LE_LFCR
}  dosStringLineEnd;

///////////////////////////////////////////////////////////////////////////////
// Functions
dosStringLength strGetLength( dosString in_string );
dosStringLength strGetConstLength( dosConstString in_string );
dosASCIIChar strUnicodeToASCIIChar( dosWord in_unicode );

dosChar charToUpper( dosChar in_char );
dosChar charToLower( dosChar in_char );

// comparision
int strCompareConstString(dosString in_string1, dosConstString in_string2);
int strCompareConstStringNoCase(dosString in_string1, dosConstString in_string2);
int strCompareString(dosString in_string1, dosString in_string2);
int strCompareStringNoCase(dosString in_string1, dosString in_string2);


//
void strInt16ToString( dosString in_buffer, dosByte in_buffer_length, dosInt16 in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );
dosStringLength strCopyConstString( dosString in_destination, dosStringLength in_destination_size, dosStringLength in_destination_pos, dosConstString in_source );
dosStringLength strCopyString( dosString in_destination, dosStringLength in_destination_size, dosStringLength in_destination_pos, dosString in_source );
void strFillString( dosString in_destination, dosStringLength in_destination_size, dosChar in_char, dosStringLength in_start_pos, dosWord in_requierd_length );
dosInt16 strFindChar( dosString in_buffer, dosChar in_char );
void strSetLength( dosString in_destination, dosStringLength in_destination_size, dosChar in_char, dosStringLength in_required_length );
void strAppendInt16ToString( dosString in_buffer, dosByte in_buffer_length, dosInt16 in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );
void strAppendConstString( dosString in_destination, dosStringLength in_destination_size, dosConstString in_source );
void strAppendString( dosString in_destination, dosStringLength in_destination_size, dosString in_source );
dosStringLength strCopyCharacter(dosString in_destination, dosStringLength in_destination_size, dosStringLength in_pos, dosChar in_char);

// hex conversion
dosChar strNibbleToHexDigit( dosByte in_nibble );
dosStringLength strWordToHexStringPos( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength in_pos, dosWord in_value );
void strWordToHexString( dosString in_buffer, dosStringLength in_buffer_length, dosWord in_value );
void strAppendWordToHexString( dosString in_buffer, dosStringLength in_buffer_length, dosWord in_value );

// byte conversion
void strByteToHexStringPos( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength in_pos, dosWord in_value );
void strByteToHexString( dosString in_buffer, dosStringLength in_buffer_length, dosWord in_value );
void strAppendByteToHexString( dosString in_buffer, dosStringLength in_buffer_length, dosWord in_value );

// word conversion
dosStringLength strWordToStringPos( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength in_pos, dosWord in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );
dosStringLength strWordToString( dosString in_buffer, dosStringLength in_buffer_length, dosWord in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );
dosStringLength strAppendWordToString( dosString in_buffer, dosStringLength in_buffer_length, dosWord in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );

// dword conversion
void strDWordToString( dosString in_buffer, dosStringLength in_buffer_length, dosDWord in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );
dosStringLength strDWordToHexStringPos( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength in_pos, dosDWord in_value );
dosStringLength strDWordToStringPos( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength in_pos, dosDWord in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );

// int32 conversion
void strInt32ToString( dosString in_buffer, dosStringLength in_buffer_length, dosInt32 in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );
void strAppendInt32ToString( dosString in_buffer, dosStringLength in_buffer_length, dosInt32 in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );
dosStringLength strInt32ToStringPos( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength in_pos, dosInt32 in_value, dosByte in_field_length, dosByte in_precision, dosByte in_options );

// parser routines
void strSkipWhitespaces(dosString in_string, dosStringLength in_buffer_length, dosStringLength* in_index);
void strSkipLineEnd(dosString in_string, dosStringLength in_buffer_length, dosStringLength* in_index, dosStringLineEnd in_line_end);
int strCheckForTokenNoCase(dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* inout_index, dosBool* in_success, dosConstString in_expected_tokens[]);
void strCheckForConstStringNoCase(dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* inout_index, dosBool* in_success, dosConstString in_string );
void strCheckForConstString(dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* inout_index, dosBool* in_success, dosConstString in_string );
void strCheckForSeparator( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* in_index, dosBool* in_success, dosChar in_char );
void strStringToInt16( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* in_index, dosBool* in_success, dosInt16* out_number );
void strStringToWord( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* in_index, dosBool* in_success, dosWord* out_number );
void strStringToDWord( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* in_index, dosBool* in_success, dosDWord* out_number );
void strStringToByte( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* in_index, dosBool* in_success, dosByte* out_number );
void strStringToFixedInt16( dosString in_buffer, dosStringLength* in_index, dosBool* in_success, dosInt16* out_number, dosByte in_fixed_point, dosWord in_divisor );
void strStringToFixedWord( dosString in_buffer, dosStringLength* in_index, dosBool* in_success, dosWord* out_number, dosByte in_fixed_point, dosWord in_divisor );
void strStringToFixedDWord( dosString in_buffer, dosStringLength* in_index, dosBool* in_success, dosDWord* out_number, dosByte in_fixed_point, dosDWord in_divisor );

dosByte strHexDigitToNibble( dosChar in_digit, dosBool* in_success );
void strHexStringToWord( dosString in_buffer, dosStringLength* in_index, dosBool* in_success, dosWord* out_number );
void strHexStringToDWord( dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* in_index, dosBool* in_success, dosDWord* out_number );

#endif
